﻿Public Class fTipoPago
    Dim daTipoPago As lbGlobalcom.dsCarteraTableAdapters.CAR_TIPOPAGOTableAdapter
    Dim daClave As lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTipoPago.Click
        Try
            If Me.DsCartera.CAR_TIPOPAGO.GetChanges IsNot Nothing Then
                CAR_TIPOPAGOBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    CAR_TIPOPAGOBindingNavigatorSaveItem.PerformClick()
                End If
            End If
            daTipoPago.Fill(DsCartera.CAR_TIPOPAGO)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub




    Private Sub CAR_TIPOPAGOBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CAR_TIPOPAGOBindingNavigatorSaveItem.Click
        Try
            Validate()
            CAR_TIPOPAGOBindingSource.EndEdit()
            daTipoPago.Update(DsCartera.CAR_TIPOPAGO)
            MessageBox.Show("Se salvarón registros con exito", "Salvar Registro", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Try
            If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                CAR_TIPOPAGOBindingSource.RemoveCurrent()
                daTipoPago.Update(DsCartera.CAR_TIPOPAGO)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
        
    End Sub

    Private Sub CAR_TIPOPAGODataGridView_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles CAR_TIPOPAGODataGridView.CellBeginEdit
        Try
            If e.ColumnIndex = 1 AndAlso CAR_TIPOPAGODataGridView.Rows(e.RowIndex).Cells(0).Value Is DBNull.Value Then
                Dim dt As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASDataTable
                dt = daClave.GetDataByIdClavePrimaria("PRO_MARCAS")
                If dt.Count Then
                    Dim dr As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASRow
                    dr = dt.Rows(0)
                    Dim Cons As lbGlobalcom.ConsecTablas = New lbGlobalcom.ConsecTablas(dr("TABLA"), dr("CAMPO"), dr("LONGITUD"))
                    CAR_TIPOPAGODataGridView.Rows(e.RowIndex).Cells(0).Value = Cons.NumeroConsec
                    Cons = Nothing
                    daTipoPago.Update(DsCartera.CAR_TIPOPAGO)
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub CAR_TIPOPAGODataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles CAR_TIPOPAGODataGridView.DataError
        MessageBox.Show(e.Exception.Message)
    End Sub

    Private Sub CAR_TIPOPAGODataGridView_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles CAR_TIPOPAGODataGridView.UserDeletedRow
        Try
            daTipoPago.Update(DsCartera.CAR_TIPOPAGO)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub CAR_TIPOPAGODataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles CAR_TIPOPAGODataGridView.UserDeletingRow
        If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub

    Private Sub fTipoPago_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If Me.DsCartera.CAR_TIPOPAGO.GetChanges IsNot Nothing Then
                CAR_TIPOPAGOBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    CAR_TIPOPAGOBindingNavigatorSaveItem.PerformClick()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub fTipoPago_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        daTipoPago = New lbGlobalcom.dsCarteraTableAdapters.CAR_TIPOPAGOTableAdapter
        daClave = New lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
    End Sub
End Class